extends Node

signal level_up(new_level:int) # 受到伤害时发出的信号

@onready var player: CharacterBody2D = $"../World/Player"
@onready var upgrade_manager: Node = $"../World/UpgradeManager"
#@onready var game_timer: Label = $"../InfoUI/GameTimer"
#@onready var experience_bar: ProgressBar = $MarginContainer/ExperienceBar
@onready var info_ui: CanvasLayer = $"../InfoUI"

var score = 0
var game_time = 0
var var_game_over = false
var experience :float = 9
var experience_to_next_level :float = 10

func _ready():
	# 初始化游戏
	TranslationServer.set_locale("zh")
	game_start_set()

func _process(delta):
	if not var_game_over:
		game_time += delta
		info_ui.update_time_display(game_time)

func game_start_set():
	upgrade_manager.enable_upgrade.connect(on_enable_upgrade)
	

func add_experience(amount):
	experience += amount

	if experience >= experience_to_next_level:
		player.level+=1
		level_up.emit(player.level)
		experience=0;
		
	info_ui.update_experience_bar(experience,experience_to_next_level)

func on_enable_upgrade(upgrade: AbilityUpgrade):
	player.weapon_manager.apply_upgrade(upgrade.id)

func game_over():
	var_game_over = true
	$"../UI/GameOverScreen".visible = true
	get_tree().paused = true 
